Skip to content

Add poll_async_job helper#185

Merged
c-fang merged 16 commits into
mainfrom
c-fang/async-job-poller
May 28, 2026
Merged

Add poll_async_job helper#185
c-fang merged 16 commits into
mainfrom
c-fang/async-job-poller

Conversation

@c-fang

@c-fang c-fang commented May 27, 2026

Copy link
Copy Markdown
Contributor

Adds a small polling utility for async-job status endpoints.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f543ae16f2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread surge/async_jobs.py Outdated
Comment thread surge/async_jobs.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6123b0ccc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread surge/async_jobs.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9209b86e6a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread surge/reports.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f473c955a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/test_async_jobs.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47671a62e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread surge/reports.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e82b079895

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread surge/reports.py Outdated
@c-fang c-fang changed the title [WIP] Add poll_async_job helper Add poll_async_job helper May 27, 2026
c-fang and others added 5 commits May 26, 2026 23:39
Drops the separate dispatch on the initial request response by treating
it as the first iteration of poll_async_job. Trades one extra
poll_interval sleep on the not-yet-ready path for ~12 fewer lines and a
single status-handling code path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Timeouts now surface as AsyncJobError with a synthetic
status="TIMEOUT" sentinel, letting callers distinguish them from
server-side failures via e.status without a separate exception class.

Also moves the deadline check after each poll instead of at the top of
the next iteration, so a job that completes during the final sleep is
honored instead of being lost to a timeout.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lets callers hand the helper a kick-off response to consume as iter 1
in place of the first check_status() call. save_report uses it so its
_check closure no longer needs to branch between request() and
check_status() based on iteration count.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@c-fang c-fang requested review from tchordia and victor-surge May 28, 2026 20:40
Comment thread surge/async_jobs.py Outdated
pending = initial_status
while True:
if pending is not None:
status, pending = pending, None

@tchordia tchordia May 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this seems like a weird way of doing this, not sure if there is a better way

Comment thread surge/async_jobs.py Outdated

Returns the terminal status dict.
"""
in_progress = set(in_progress_statuses)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should the constants be sets?

Make the default status collections frozensets so membership checks
don't rebuild sets on every call, and drop the per-call set() wrapping.

Restructure the poll loop to seed the first status and fetch the next
one at the end of the body, removing the pending/swap dance.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be2bae68f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread surge/async_jobs.py
Comment on lines +54 to +55
if value in completed_statuses:
return status

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check the deadline before accepting completion

When a poll response arrives after poll_time has already elapsed, this branch still returns it as successful because the deadline is only checked later for in-progress statuses. For example, with an initial IN_PROGRESS, poll_time=1, and a delayed/overslept next check_status() returning COMPLETED after the deadline, callers get success despite the documented maximum wait; the fresh evidence is that this revision still returns completed statuses before any post-poll deadline check.

Useful? React with 👍 / 👎.

Reframes poll_time in the docstring as the budget for time spent waiting
between polls rather than a hard wall-clock ceiling, matching the
implementation that honors a terminal status already returned by a poll.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@c-fang c-fang merged commit 8009bf9 into main May 28, 2026
2 checks passed
@c-fang c-fang deleted the c-fang/async-job-poller branch May 28, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants